import axios from "axios";
const service = axios.create({
  withCredentials: false,
  timeout: 5000,
  baseURL: import.meta.env.VITE_BASE_URL || "",
});

service.interceptors.request.use(
  (config) => {
    return config;
  },
  (error) => {
    return Promise.reject(error);
  },
);

service.interceptors.response.use(
  (response) => {
    const res = response.data;
    if (response.status !== 200) {
      return Promise.reject(res.msg || "Error");
    } else {
      console.log("res: ", res);
      return res;
    }
  },
  (error) => {
    console.log("err" + error);
    return Promise.reject(error.message);
  },
);
export default {
  get(url, config) {
    return service.get(url, config);
  },

  post(url, data, config) {
    return service.post(url, data, config);
  },

  put(url, data, config) {
    return service.put(url, data, config);
  },

  delete(url, config) {
    return service.delete(url, config);
  },
};
